package com.nageoffer.jobtrain.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.jobtrain.admin.dto.req.*;
import com.nageoffer.jobtrain.admin.dto.resp.ContestAddOjQuestionRespDTO;
import com.nageoffer.jobtrain.admin.dto.resp.ContestEditRespDTO;
import com.nageoffer.jobtrain.admin.dto.resp.ContestPageRespDTO;
import com.nageoffer.jobtrain.admin.service.ContestService;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 竞赛接口控制层
 * author：唐晨
 */
@RestController
@RequiredArgsConstructor
public class ContestController {
    private final ContestService contestService;

    /**
     * 竞赛分页请求-开始结束时间/标题
     */
    @PostMapping("/api/job-train/admin/contest/page")
    public Result<IPage<ContestPageRespDTO>> contestPageList(@RequestBody ContestPageReqDTO requestParam) {
        return Results.success(contestService.contestPageList(requestParam));
    }

    /**
     * 新增竞赛基本信息
     */
    @PostMapping("/api/job-train/admin/contest/base-info/add")
    public Result<ContestAddOjQuestionRespDTO> addContestBaseInfo(@RequestBody ContestAddBaseInfoReqDTO requestParam) {
        return Results.success(contestService.addContestBaseInfo(requestParam));
    }

    /**
     * 编辑竞赛详情
     */
    @PostMapping("/api/job-train/admin/contest/edit")
    public Result<ContestEditRespDTO> editContest(@RequestBody ContestEditReqDTO requestParam) {
        return Results.success(contestService.editContest(requestParam));
    }

    /**
     * 修改竞赛详情
     */
    @PostMapping("/api/job-train/admin/contest/update")
    public Result<Void> updateContest(@RequestBody ContestUpdateReqDTO requestParam) {
        contestService.updateContest(requestParam);
        return Results.success();
    }

    /**
     * 删除竞赛详情
     */
    @DeleteMapping("/api/job-train/admin/contest/delete")
    public Result<Void> deleteContest(@RequestBody ContestDeleteReqDTO requestParam) {
        contestService.deleteContest(requestParam);
        return Results.success();
    }

    /**
     * 发布竞赛
     */
    @PostMapping("/api/job-train/admin/contest/publish")
    public Result<Void> publishContest(@RequestBody ContestPublishReqDTO requestParam) {
        contestService.publishContest(requestParam);
        return Results.success();
    }

    /**
     * 撤销发布竞赛
     */
    @PostMapping("/api/job-train/admin/contest/revoke-publish")
    public Result<Void> revokePublishContest(@RequestBody ContestRevokePublishReqDTO requestParam) {
        contestService.revokePublishContest(requestParam);
        return Results.success();
    }
}
